﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HousingDistribution
{
    public partial class FormDBConf : Form
    {
        public FormDBConf()
        {
            InitializeComponent();
            this.textBoxPWD.PasswordChar = '*';

            ReadData();
        }

        private void ReadData()
        {
            textBoxServer.Clear();
            textBoxDB.Clear();
            textBoxUID.Clear();
            textBoxPWD.Clear();

            DBConfInfo info = DBConf.Instance().ReadData();

            textBoxServer.Text = info.server;
            textBoxDB.Text = info.db;
            textBoxUID.Text = info.uid;
            textBoxPWD.Text = info.pwd;
        }

        private void SaveData()
        {
            DBConfInfo info = DBConf.Instance().ReadData();

            info.server = textBoxServer.Text;
            info.db = textBoxDB.Text;
            info.uid = textBoxUID.Text;
            info.pwd = textBoxPWD.Text;
            info.port = port;

            DBConf.Instance().Save(info);

            //重新设置数据库信息
            DBProc.Instance().SetServerInfo(info.server, info.db, info.port, info.uid, info.pwd);

            DataDictionary.Instance().ReadHousingInfoFromMySql();
        }

        private void BtnSave_Click(object sender, EventArgs e)
        {
            SaveData();
            this.Close();
        }
        private void BtnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private int port = 3306;

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBoxDisplayPwd.Checked == false)
                this.textBoxPWD.PasswordChar = '*';
            else
                this.textBoxPWD.PasswordChar = Convert.ToChar(0);
        }
    }
}
